package 力扣日常刷题.木22一月.第10天0118;

/**
 * @author 帅小伙
 * @date 2022/1/18
 * @description
 */
public class Demo20动态规划中等石子游戏 {

    public boolean stoneGame(int[] piles) {
        int n = piles.length;
        if(n == 0) return false;
        int[][] dp = new int[n][n];

        for (int i = n-1; i >=0 ; i--) {
            dp[i][i] = piles[i];
            for (int j = i+1; j < n; j++) {
                dp[i][j] = Math.max((piles[i]-dp[i+1][j]),(piles[j] - dp[i][j-1]));
            }
        }
        return dp[0][n-1] > 0;
    }
}
